package signalprocessing;

import ikelib.PlotColor;
import ikelib.wintime;

import java.awt.Rectangle;

/**
 * 
 */

/**
 * @author ikechan
 *
 */
public class PlotPaneYX extends PlotPane {

	public PlotPaneYX(){
		super();
	}
	
	
	/**
	 * 
	 * Pointを計算する
	 * @param g
	 */
	protected boolean PointCalcXY(Rectangle r){
		//System.out.println("PolyCalc 1");
		ViewRect = r;
		
		double yamp = (ViewRect.height-1)/2.0;
		double xamp = (ViewRect.width-1)/2.0;
		
		double dmaxy = -Double.MAX_VALUE;
		double dminy = Double.MAX_VALUE;
		double dmaxx = -Double.MAX_VALUE;
		double dminx = Double.MAX_VALUE;
		Integer[] id = getChannel();
		
		double[] dx = getDataX(DataXCh);
		if(dx==null) return false;
		for(int i=0;i<id.length;i++){
			if(id[i]==null) return false;
			double dy[] = getData(id[i]);
			
			int dlen = dy.length;
			if(dlen>dx.length){
				dlen=dx.length;
			}
			int[] datx = new int[dlen];
			int[] daty = new int[dlen];
			for(int j=0;j<dlen;j++){
				double datay = dy[j];
				if(datay < dminy) dminy = datay;
				if(datay > dmaxy) dmaxy = datay;
				daty[j] = (int)(-(datay-YScale.ScaleCenter)/YScale.ScaleAmp * yamp);
				double datax = dx[j];
				if(datax < dminx) dminx = datax;
				if(datax > dmaxx) dmaxx = datax;
				datx[j] = (int)((datax-XScale.ScaleCenter)/XScale.ScaleAmp * xamp);
			}
			PolyDataX.put(id[i], datx);
			PolyDataY.put(id[i], daty);
			PolyDataLen.put(id[i], dlen);
		}
		YScale.TempDispDataMax = dmaxy;
		YScale.TempDispDataMin = dminy;
		XScale.TempDispDataMax = dmaxx;
		XScale.TempDispDataMin = dminx;
		return true;
	}
	/* (non-Javadoc)
	 * @see PlotPane#onDataChange()
	 */
	@Override
	void onDataChange() {
		
	}
	/* (non-Javadoc)
	 * @see PlotPane#PolyLineCalc()
	 */
	@Override
	protected boolean PolyLineCalc() {
		//return PointCalc();
		return true;
	}
	/* (non-Javadoc)
	 * @see PlotPane#PointCalc()
	 */
	@Override
	boolean PointCalc() {
		return false;
	}
	/* (non-Javadoc)
	 * @see PlotPane#repaintAllComponent()
	 */
	@Override
	void repaintAllComponent() {
		
	}

}
